﻿using System;
using System.Collections.Generic;
using GeoAPI.Geometries;

namespace YJKGridTopologyCal.Utilities
{
	public class UniqueCoordinateArrayFilter : ICoordinateFilter
	{
		public static Coordinate[] FilterCoordinates(Coordinate[] coords)
		{
			UniqueCoordinateArrayFilter uniqueCoordinateArrayFilter = new UniqueCoordinateArrayFilter();
			for (int i = 0; i < coords.Length; i++)
			{
				uniqueCoordinateArrayFilter.Filter(coords[i]);
			}
			return uniqueCoordinateArrayFilter.Coordinates;
		}

		public Coordinate[] Coordinates
		{
			get
			{
				return this._list.ToArray();
			}
		}

		public void Filter(Coordinate coord)
		{
			if (!this._list.Contains(coord))
			{
				this._list.Add(coord);
			}
		}

		private readonly List<Coordinate> _list = new List<Coordinate>();
	}
}
